package com.hntech.spring.zookpeeper;

import org.apache.curator.CuratorZookeeperClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

/**
 * @Autho changqi.wu
 * @Date 路在脚下，使劲踩！
 */
public class ZkClient {

    public static void main(String[] args) throws Exception {

//        CuratorZookeeperClient client = new CuratorZookeeperClient();

        CuratorFramework curatorFramework = CuratorFrameworkFactory.builder()
                .connectString("192.168.1.5:2182")
                .sessionTimeoutMs(5000)
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .build();

        curatorFramework.start();

        //crud

//        curatorFramework.create();
//        curatorFramework.setData();
//        curatorFramework.getData();
//        curatorFramework.delete();

        create(curatorFramework);


    }

    private static void create(CuratorFramework curatorFramework) throws Exception {
        curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/data/zk1","zk1".getBytes());
    }


}
